package com.hibernate.hql;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.classic.Session;
import org.junit.Test;

import com.hibernate.utils.HibernateUtil;

/**
 * hibernate之hql自带list和map集合查询
 * @author LC
 *
 */
public class ListMapQueryTest extends HibernateUtil {
	
	/**
	 * hql自带list测试
	 */
	@Test
	public void testListQuery() {
		Session session = sessionFactory.openSession() ;
		String hql = "select new list(cid,cname) from Classes" ;
		Query query = session.createQuery(hql) ;
		//可使用debug模式分析内存数据结构
		query.list() ;
		session.close() ;
	}
	
	/**
	 * hql自带map测试
	 */
	@Test
	public void testMapQuery() {
		Session session = sessionFactory.openSession() ;
		/**
		 * Map
		 *   {key:aaa,value:cid的值}
		 *   {key:bbb,value:cname的值}
		 */
		String hql = "select new map(cid as aaa, cname as bbb) from Classes" ;
		Query query = session.createQuery(hql) ;
		//可使用debug模式分析内存数据结构
		query.list() ;
		session.close() ;
	}
}
